import requests
import asyncio
import aiohttp


# page = 1

# for i in range(1,65):
#     print(f'第{page}页')
#     url = f'https://www.cwl.gov.cn/cwl_admin/front/cwlkj/search/kjxx/findDrawNotice?name=ssq&pageNo={page}&pageSize=30&systemType=PC'
#
#     content = requests.get(url)
#
#     items = content.json()
#     for item in items['result']:
#         code = item['code']
#         num = item['red']+','+item['blue']
#         print(f'日期：{code},号码：{num}')
#     page += 1
headers = {
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36',
    'referer':'https://www.cwl.gov.cn/ygkj/wqkjgg/',
    'cookie':'HMF_CI=580b59165238559a9d74ac84eda0e534228190e3f6baccde38cd81e8b1f28131cedcd03c23769424ac6255df48f8aeeb80b43a8a161d3bf41a5d06a192de47a435; 21_vq=5'
}

async def fetch(session, url):
    async with session.get(url) as response:
        print(f'正在爬取{url}')
        items = await response.json(content_type=None)
        for item in items['result']:
            code = item['code']
            num = item['red'] + ',' + item['blue']
            print(f'日期：{code},号码：{num}')

async def main():
    async with aiohttp.ClientSession(headers=headers) as session:

        urls = [f'https://www.cwl.gov.cn/cwl_admin/front/cwlkj/search/kjxx/findDrawNotice?name=ssq&pageNo={i}&pageSize=30&systemType=PC' for i in range(1,2)]

        task = [fetch(session,url)for url in urls]
        await asyncio.gather(*task)


asyncio.run(main())











